home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-9.000 / irsim-9 / src / include / net_macros.h < prev    next >
C/C++ Source or Header  |  1993-01-15  |  4KB  |  170 lines

  1. /* 
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     ********************************************************************* 
  13.  */
  14.  
  15. /* 
  16.  * Auxiliary net macros.
  17.  */
  18.  
  19. #ifndef    NULL
  20. #include <stdio.h>
  21. #endif
  22.  
  23. #ifndef    NCHAN
  24. #include "net.h"
  25. #endif
  26.  
  27. /*
  28.  * Swap the 2 nodes
  29.  */
  30. #define    SWAP_NODES( N1, N2 )        SWAP( nptr, N1, N2 )
  31.  
  32.  
  33. /*
  34.  * if FLAG is not set in in NODE->nflags, Link NODE to the head of LIST
  35.  * using the temporary entry (n.next) in the node structure.  This is
  36.  * used during net read-in/change to build lists of affected nodes.
  37.  */
  38. #define    LINK_TO_LIST( NODE, LIST, FLAG )    \
  39.   {                        \
  40.     if( ((NODE)->nflags & (FLAG)) == 0 )    \
  41.       {                        \
  42.     (NODE)->nflags |= (FLAG);        \
  43.     (NODE)->n.next = (LIST);        \
  44.     LIST = (NODE);                \
  45.       }                        \
  46.   }                        \
  47.  
  48.  
  49.  
  50. /*
  51.  * Allocate a new "Tlist" pointer.
  52.  */
  53. #define    NEW_LINK( LP )                        \
  54.   {                                \
  55.     if( (LP = freeLinks) == NULL )                \
  56.     LP = (lptr) MallocList( sizeof( struct Tlist ), 1 );    \
  57.     freeLinks = (LP)->next;                    \
  58.   }
  59.  
  60.  
  61. /*
  62.  * Return "Tlist" pointer LP to free pool.
  63.  */
  64. #define    FREE_LINK( LP )            \
  65.   {                    \
  66.     (LP)->next = freeLinks;        \
  67.     freeLinks = (LP);            \
  68.   }
  69.  
  70.  
  71. /*
  72.  * Allocate a new Transistor.
  73.  */
  74. #define    NEW_TRANS( T )                        \
  75.   {                                \
  76.     if( (T = freeTrans) == NULL )                \
  77.     T = (tptr) MallocList( sizeof( struct Trans ), 1 );    \
  78.     freeTrans = (tptr) (T)->gate;                \
  79.   }
  80.  
  81.  
  82. /*
  83.  * Return transistor record T to free pool.
  84.  */
  85. #define    FREE_TRANS( T )            \
  86.   {                    \
  87.     (T)->gate = (nptr) freeTrans;    \
  88.     freeTrans = (T);            \
  89.   }                    \
  90.  
  91.  
  92. /*
  93.  * Add transistor T to the list of transistors connected to that list.
  94.  * The transistor is added at the head of the list.
  95.  */
  96. #define CONNECT( LIST, T )    \
  97.   {                \
  98.     register lptr  newl;    \
  99.                 \
  100.     NEW_LINK( newl );        \
  101.     newl->xtor = (T);        \
  102.     newl->next = (LIST);    \
  103.     LIST = newl;        \
  104.   }
  105.  
  106.  
  107. /*
  108.  * Transistors that have their drain/source shorted are NOT connected
  109.  * to the network, they are instead linked as a doubly linked list
  110.  * using the scache/dcache fields.
  111.  */
  112. #define LINK_TCAP( T )            \
  113.   {                    \
  114.     (T)->dcache.t = tcap;        \
  115.     (T)->scache.t = tcap->scache.t;    \
  116.     tcap->scache.t->dcache.t = (T);    \
  117.     tcap->scache.t = (T);        \
  118.     tcap->x.pos ++;            \
  119.   }
  120.  
  121.  
  122. #define    UNLINK_TCAP( T )            \
  123.   {                        \
  124.     (T)->dcache.t->scache.t = (T)->scache.t;    \
  125.     (T)->scache.t->dcache.t = (T)->dcache.t;    \
  126.     (T)->ttype &= ~TCAP;            \
  127.     tcap->x.pos --;                \
  128.   }
  129.  
  130.  
  131. /*
  132.  * Replace the first ocurrence of transistor OLD by NEW on LIST.
  133.  */
  134. #define    REPLACE( LIST, OLD, NEW )            \
  135.   {                            \
  136.     register lptr  lp;                    \
  137.                             \
  138.     for( lp = (LIST); lp != NULL; lp = lp->next )    \
  139.       {                            \
  140.     if( lp->xtor == OLD )                \
  141.       {                        \
  142.         lp->xtor = NEW;                \
  143.         break;                    \
  144.       }                        \
  145.       }                            \
  146.   }                            \
  147.  
  148.  
  149. /*
  150.  * Remove the entry for transistor T from LIST, and return it to the
  151.  * free pool.
  152.  */
  153. #define    DISCONNECT( LIST, T )            \
  154.   {                        \
  155.     register lptr  li, *lip;            \
  156.                         \
  157.     lip = &(LIST);                \
  158.     while( (li = *lip) != NULL )        \
  159.       {                        \
  160.     if( li->xtor == (T) )            \
  161.       {                    \
  162.         *lip = li->next;            \
  163.         FREE_LINK( li );            \
  164.         break;                \
  165.       }                    \
  166.     lip = &(li->next);            \
  167.       }                        \
  168.   }                        
  169.  
  170.